/**
 * 打印 hello world
 */
export const sayHello = function (): string {
    console.log("hello world");
    return "hello world";
};

export const testFn = (num1: number, num2: number): number => {
    return num1 + num2;
};

interface GlobalValueType {
    /** 建筑工地 */
    construction_sites: ConstructionSite[];
    /** 建筑物 */
    structures: AnyStructure[];
    /** 矿 */
    sources: Source[];
}

/** 全局变量，避免重复 .find 耽误cpu时间 */
const GlobalValue: GlobalValueType = {
    construction_sites: [],
    structures: [],
    sources: []
};

function initGlobalValue(): void {
    const room = Object.values(Game.rooms)[0];

    GlobalValue.construction_sites = room.find(FIND_CONSTRUCTION_SITES);

    GlobalValue.structures = room.find(FIND_STRUCTURES, {
        filter: (structure) => {
            return (
                structure.structureType === STRUCTURE_EXTENSION ||
                structure.structureType === STRUCTURE_SPAWN ||
                structure.structureType === STRUCTURE_CONTAINER ||
                structure.structureType === STRUCTURE_TOWER ||
                structure.structureType === STRUCTURE_ROAD ||
                structure.structureType === STRUCTURE_WALL ||
                structure.structureType === STRUCTURE_RAMPART
            );
        }
    });

    GlobalValue.sources = room.find(FIND_SOURCES);
}

export { GlobalValue, initGlobalValue };
